﻿var orgDateMessage = ""; function CheckDate(sender, args) {
    var prefix = sender.id.toString(); var arrprefix = prefix.split("_"); var strprefix = ""; var strsourceid = ""; var arrlen = arrprefix.length - 1; for (i = 0; i < arrlen; i++) { strprefix = strprefix + arrprefix[i].toString() + "_"; }
    strsourceid = arrprefix[arrlen]; var cvalD = document.getElementById(strprefix + 'ddlDay'); var cvalM = document.getElementById(strprefix + 'ddlMonth'); var cvalY = document.getElementById(strprefix + 'ddlYear'); var allowgtoday = document.getElementById(strprefix + 'txtAllowGreaterThanToday'); var istravelinsurance = document.getElementById(strprefix + 'txtIsTravelInsurance'); var isnotlessthantoday = document.getElementById(strprefix + 'txtIsNotLessThanToday'); var csvDate = document.getElementById(prefix); var isvalid = true; var isDvalid = true; var isMvalid = true; var isYvalid = true; var y = parseInt(cvalY.value); var m = parseInt(cvalM.value); var d = parseInt(cvalD.value); if (cvalD.value == -1 && cvalM.value == -1 && cvalY.value == -1) { }
    else if (cvalD.value == -1 || cvalM.value == -1 || cvalY.value == -1) {
        if (csvDate.textContent) { csvDate.textContent = ""; }
        else { csvDate.innerText = ""; }
        if (cvalD.value == -1) isDvalid = false; if (cvalM.value == -1) isMvalid = false; if (cvalY.value == -1) isYvalid = false;
    }
    else {
        isvalid = true; isDvalid = true; isMvalid = true; isYvalid = true; if (y % 4 == 0 || y % 2000 == 0 || y % 400 == 0) {
            if (m == 2 && d > 29) {
                if (csvDate.textContent) { }
                else { }
                isMvalid = false; isDvalid = false; isvalid = false;
            } 
        }
        else if (m == 2) {
            if (d > 28) {
                if (csvDate.textContent) { }
                else { }
                isDvalid = false; isMvalid = false; isvalid = false;
            } 
        }
        if (m == 4 || m == 6 || m == 9 || m == 11) {
            if (d > 30) {
                if (csvDate.textContent) { }
                else { }
                isDvalid = false; isMvalid = false; isvalid = false;
            } 
        }
        valallowgtoday = parseInt(allowgtoday.value); if (valallowgtoday == 0 && isvalid == true) {
            var now = new Date(); var nowM = now.getMonth() + 1; var nowY = now.getYear(); var nowD = now.getDate(); if (nowY < 1900) { nowY += 1900; }
            if (y == nowY) {
                if (m >= nowM) {
                    if (d > nowD && nowM == m) {
                        if (csvDate.textContent) { }
                        else { }
                        isDvalid = false; isvalid = false;
                    }
                    else if (m > nowM) {
                        if (csvDate.textContent) { }
                        else { }
                        isMvalid = false; isvalid = false;
                    } 
                } 
            }
            else if (y > nowY) {
                if (csvDate.textContent) { }
                else { }
                isYvalid = false; isvalid = false;
            } 
        }
        valnotlessthantoday = parseInt(isnotlessthantoday.value); if (valnotlessthantoday == 1 && isvalid == true) {
            var now = new Date(); var nowM = now.getMonth(); var nowY = now.getFullYear(); var nowD = now.getDate(); var dateNow = new Date(nowY, nowM, nowD); var dateSel = new Date(y, m - 1, d); if (dateSel < dateNow) { isYvalid = false; isvalid = false; }
            else { isYvalid = true; isvalid = true; } 
        }
        valtravelinsurance = parseInt(istravelinsurance.value); if (valtravelinsurance == 1 && isvalid == true) {
            var now = new Date(); var nowM = now.getMonth(); var nowY = now.getFullYear(); var nowD = now.getDate(); var dateNow = new Date(nowY, nowM, nowD); var usrctrlNameStart = ''; var usrctrlNameEnd = ''; var ddlPolicyType = document.getElementById('ctl00_ContentPlaceHolder1_ddlPolicyType'); if (ddlPolicyType.value == 'IND') {
                var ddlTripType = document.getElementById('<%=ddlTripType.ClientID%>'); usrctrlNameStart = 'ctl00_ContentPlaceHolder1_usrS1TravelStartDate_'; var dt1 = document.getElementById(usrctrlNameStart + 'ddlDay').value; var mon1 = document.getElementById(usrctrlNameStart + 'ddlMonth').value; var yr1 = document.getElementById(usrctrlNameStart + 'ddlYear').value; usrctrlNameEnd = 'ctl00_ContentPlaceHolder1_usrS1TravelEndDate_'; var dt2 = document.getElementById(usrctrlNameEnd + 'ddlDay').value; var mon2 = document.getElementById(usrctrlNameEnd + 'ddlMonth').value; var yr2 = document.getElementById(usrctrlNameEnd + 'ddlYear').value; var date1 = new Date(yr1, mon1 - 1, dt1); var date2 = new Date(yr2, mon2 - 1, dt2); if (date2 < date1 && (dt2 != -1 && mon2 != -1 && yr2 != -1))
                { isYvalid = false; isvalid = false; }
                else if (date1 < dateNow)
                { isYvalid = false; isvalid = false; }
                else { isYvalid = true; isvalid = true; } 
            }
            else if (ddlPolicyType.value == 'FML') {
                var ddlTripType = document.getElementById('<%=ddlTripType.ClientID%>'); usrctrlNameStart = 'ctl00_ContentPlaceHolder1_usrS3TravelStartDate_'; var s3dt1 = document.getElementById(usrctrlNameStart + 'ddlDay').value; var s3mon1 = document.getElementById(usrctrlNameStart + 'ddlMonth').value; var s3yr1 = document.getElementById(usrctrlNameStart + 'ddlYear').value; usrctrlNameEnd = 'ctl00_ContentPlaceHolder1_usrS3TravelEndDate_'; var s3dt2 = document.getElementById(usrctrlNameEnd + 'ddlDay').value; var s3mon2 = document.getElementById(usrctrlNameEnd + 'ddlMonth').value; var s3yr2 = document.getElementById(usrctrlNameEnd + 'ddlYear').value; var s3date1 = new Date(s3yr1, s3mon1 - 1, s3dt1); var s3date2 = new Date(s3yr2, s3mon2 - 1, s3dt2); if (s3date2 < s3date1 && (s3dt2 != -1 && s3mon2 != -1 && s3yr2 != -1))
                { isYvalid = false; isvalid = false; }
                else if (s3date1 < dateNow) { isYvalid = false; isvalid = false; }
                else { isYvalid = true; isvalid = true; } 
            }
            else if (ddlPolicyType.value == 'INS') {
                var ddlTripType = document.getElementById('<%=ddlTripType.ClientID%>'); usrctrlNameStart = 'ctl00_ContentPlaceHolder1_usrS5TravelStartDate_'; var s5dt1 = document.getElementById(usrctrlNameStart + 'ddlDay').value; var s5mon1 = document.getElementById(usrctrlNameStart + 'ddlMonth').value; var s5yr1 = document.getElementById(usrctrlNameStart + 'ddlYear').value; usrctrlNameEnd = 'ctl00_ContentPlaceHolder1_usrS5TravelEndDate_'; var s5dt2 = document.getElementById(usrctrlNameEnd + 'ddlDay').value; var s5mon2 = document.getElementById(usrctrlNameEnd + 'ddlMonth').value; var s5yr2 = document.getElementById(usrctrlNameEnd + 'ddlYear').value; var s5date1 = new Date(s5yr1, s5mon1 - 1, s5dt1); var s5date2 = new Date(s5yr2, s5mon2 - 1, s5dt2); if (s5date2 < s5date1 && (s5dt2 != -1 && s5mon2 != -1 && s5yr2 != -1)) { isYvalid = false; isvalid = false; }
                else if (s5date1 < dateNow) { isYvalid = false; isvalid = false; }
                else { isYvalid = true; isvalid = true; } 
            }
            if (isvalid) { var cS1valDstart = document.getElementById(usrctrlNameStart + 'ddlDay'); var cS1valMstart = document.getElementById(usrctrlNameStart + 'ddlMonth'); var cS1valYstart = document.getElementById(usrctrlNameStart + 'ddlYear'); var cS1valDend = document.getElementById(usrctrlNameEnd + 'ddlDay'); var cS1valMend = document.getElementById(usrctrlNameEnd + 'ddlMonth'); var cS1valYend = document.getElementById(usrctrlNameEnd + 'ddlYear'); if (cS1valDstart != null && cS1valDend != null) { cS1valDstart.style.backgroundColor = 'transparent'; cS1valDstart.style.border = 'Solid 1px #0066FF'; cS1valDstart.style.fontWeight = ''; cS1valMstart.style.backgroundColor = ''; cS1valMstart.style.border = ''; cS1valMstart.style.fontWeight = ''; cS1valYstart.style.backgroundColor = ''; cS1valYstart.style.border = ''; cS1valYstart.style.fontWeight = ''; cS1valDend.style.backgroundColor = 'transparent'; cS1valDend.style.border = 'Solid 1px #0066FF'; cS1valDend.style.fontWeight = ''; cS1valMend.style.backgroundColor = ''; cS1valMend.style.border = ''; cS1valMend.style.fontWeight = ''; cS1valYend.style.backgroundColor = ''; cS1valYend.style.border = ''; cS1valYend.style.fontWeight = ''; } } 
        }
        if (isvalid == false) { cvalD.style.backgroundColor = '#fcc'; cvalD.style.border = 'Solid 1px #f00'; cvalM.style.backgroundColor = '#fcc'; cvalM.style.border = 'Solid 1px #f00'; cvalY.style.backgroundColor = '#fcc'; cvalY.style.border = 'Solid 1px #f00'; }
        else { cvalD.style.backgroundColor = ''; cvalD.style.border = ''; cvalD.style.fontWeight = ''; cvalM.style.backgroundColor = ''; cvalM.style.border = ''; cvalM.style.fontWeight = ''; cvalY.style.backgroundColor = ''; cvalY.style.border = ''; cvalY.style.fontWeight = ''; } 
    }
    args.IsValid = isvalid; return;
}
function IsEnableDateValidation(prefix, onOff) {
    ValidatorEnable(document.getElementById(prefix + "_rfvDay"), onOff); ValidatorEnable(document.getElementById(prefix + "_rfvMonth"), onOff)
    ValidatorEnable(document.getElementById(prefix + "_rfvYear"), onOff); ValidatorEnable(document.getElementById(prefix + "_csvDate"), onOff);
}